<?php

declare(strict_types=1);

namespace SixShop\Wangdian;

use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
use SixShop\Wangdian\Config\Config;

/**
 * Factory class for easy SDK initialization
 */
class WangdianFactory
{
    /**
     * Create a client for sandbox environment
     */
    public static function createSandboxClient(
        string $sid,
        string $appKey,
        string $appSecret,
        ?ClientInterface $httpClient = null,
        ?LoggerInterface $logger = null
    ): Client {
        $config = Config::sandbox($sid, $appKey, $appSecret);
        return new Client($config, $httpClient, $logger);
    }

    /**
     * Create a client for production environment
     */
    public static function createProductionClient(
        string $sid,
        string $appKey,
        string $appSecret,
        ?ClientInterface $httpClient = null,
        ?LoggerInterface $logger = null
    ): Client {
        $config = Config::production($sid, $appKey, $appSecret);
        return new Client($config, $httpClient, $logger);
    }

    /**
     * Create a client with custom configuration
     */
    public static function createClient(
        Config $config,
        ?ClientInterface $httpClient = null,
        ?LoggerInterface $logger = null
    ): Client {
        return new Client($config, $httpClient, $logger);
    }

    /**
     * Create a configuration instance
     */
    public static function createConfig(
        string $sid,
        string $appKey,
        string $appSecret,
        string $baseUrl = Config::SANDBOX_BASE_URL,
        int $timeout = 30,
        bool $debug = false,
        ?string $logFile = null
    ): Config {
        return new Config(
            sid: $sid,
            appKey: $appKey,
            appSecret: $appSecret,
            baseUrl: $baseUrl,
            timeout: $timeout,
            debug: $debug,
            logFile: $logFile
        );
    }
}